<?php
/**
 * Created by 784855684@qq.com.
 * Link: https://github.com/lichtung/inframe
 * User: linzh
 * Date: 6/25/17
 * Time: 4:51 PM
 */



namespace inframe\helper;


final class Validator
{
    /**
     * 验证是否是邮箱
     * @param string $email
     * @return bool
     */
    public static function isEmail($email)    {
        $res = preg_match("/^([0-9A-Za-z\\-_\\.]+)@[0-9a-z]+\\.[a-z]{1,6}(\\.[a-z]{2})?$/i", $email, $match);
        return $res === 1;
    }

    public static function isPhone($phone)    {
        return preg_match("/^1[34578]\\d{9}$/", $phone) === 1;
    }

    public static function isPasswordInvalid($password)    {
//        $r4 = '/[~!@#$%^&*()\-_=+{};:<,.>?]/';  // special char
        if (preg_match_all('/[A-Z]/', $password, $o) < 1) {
            return "密码必须包含至少一个大写字母！";
        }
        if (preg_match_all('/[a-z]/', $password, $o) < 1) {
            return "密码必须包含至少一个小写字母！";
        }
        if (preg_match_all('/[0-9]/', $password, $o) < 1) {
            return "密码必须包含至少一个数字！";
        }
        if (strlen($password) < 8) {
            return "密码必须包含至少含有8个字符！";
        }
        return '';
    }

}